package com.beiding.sqlbuilder.impl;

import com.beiding.sqlbuilder.*;

import java.util.*;

public class SimpleReturnBuilder implements ReturnBuilder {

    private Tables tableHolder = new Tables();

    private Collection<TableField> tableFields = new ArrayList<>();


    SimpleReturnBuilder(TableField... tableFields) {
        this.tableFields.addAll(Arrays.asList(tableFields));
    }

    SimpleReturnBuilder(Collection<TableField> tableFields) {
        this.tableFields.addAll(tableFields);
    }

    public SimpleReturnBuilder p(TableField... tableFields) {
        this.tableFields.addAll(Arrays.asList(tableFields));
        return this;
    }

    @Override
    public String build(BuilderContext builderContext) {
        List<Parameter> parameters = ConditionUtils.createParameters(tableHolder, tableFields);
        List<ParameterHolder> list = ConditionUtils.buildParameterHolders(parameters, builderContext.getParameterHandlers());
        return builderContext.getReturnHandler().handle(list);
    }


    @Override
    public List<Table> getTables() {
        return tableHolder.getTables();
    }


}
